home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************/
- /* */
- /* Module: getopt.c - Scan environment area for matching string */
- /* */
- /* Programmer: David Beckemeyer, with modifications by George R. Woodside */
- /* */
- /* Date: January 7, 1987 */
- /* */
- /* Function: Search the environment area for a named environment string. */
- /* Return a null if string is not found. */
- /* Return a pointer to the associated environment variable if */
- /* the input string is found. */
- /* */
- /****************************************************************************/
-
- #include <basepage.h>
-
- char *getenv(ustring) /* note that return is a char * */
- char *ustring;
- {
- char *temp;
- char *user;
- struct b_page *bpage; /* Basepage pointer */
-
- bpage = _base; /* assign the basepage pointer */
- temp=(char *)(bpage->p_env); /* pointer to environment strings */
-
- while ((*temp)!=0) /* while there are strings to check */
- {
- user=ustring; /* load start of user's string */
- while((*temp)==(*user)) /* while the characters match, */
- {
- temp++; /* move environment up */
- user++; /* and user string up */
- } /* end bytes match */
-
- /**********************************************************************/
- /* If the environment string is now at "=", and the user string is */
- /* at it's end, then we have a match. */
- /**********************************************************************/
-
- if ((*temp) == '=' && (*user) == 0) /* if it matched, */
- {
- if (*(++temp)==0) /* and next byte is null, */
- temp++; /* point to next value */
- return temp; /* and return that */
- }
-
- if ((*temp)!=0) /* if environment string not ended */
- {
- while ((*(temp++))!=0); /* skip to the end */
- }
- else /* otherwise, */
- temp++; /* move to next string */
- }
- return(0); /* if we get here, no matches */
- }
-